package com.xiaomei.manager.model;

import java.util.ArrayList;
import java.util.List;

public class SysResource {
	
	 private Long id; //编号
	    private String name; //资源名称
	    private ResourceType type = ResourceType.menu; //资源类型
	    private String url; //资源路径
	    private String permission; //权限字符串
	    private Long parentId; //父编号
	    private String parentIds; //父编号列表
	    private Boolean available = Boolean.FALSE;
	    
	    private List<SysResource> lowerResources = new ArrayList<SysResource>();// 下级菜单

	    public static enum ResourceType {
	        menu("菜单"), button("按钮");

	        private final String info;
	        private ResourceType(String info) {
	            this.info = info;
	        }

	        public String getInfo() {
	            return info;
	        }
	    }



	    public Long getId() {
	        return id;
	    }

	    public void setId(Long id) {
	        this.id = id;
	    }

	    public String getName() {
	        return name;
	    }

	    public void setName(String name) {
	        this.name = name;
	    }

	    public ResourceType getType() {
	        return type;
	    }

	    public void setType(ResourceType type) {
	        this.type = type;
	    }

	    public String getUrl() {
	        return url;
	    }

	    public void setUrl(String url) {
	        this.url = url;
	    }

	    public String getPermission() {
	        return permission;
	    }

	    public void setPermission(String permission) {
	        this.permission = permission;
	    }

	    public Long getParentId() {
	        return parentId;
	    }

	    public void setParentId(Long parentId) {
	        this.parentId = parentId;
	    }

	    public String getParentIds() {
	        return parentIds;
	    }

	    public void setParentIds(String parentIds) {
	        this.parentIds = parentIds;
	    }

	    public Boolean getAvailable() {
	        return available;
	    }

	    public void setAvailable(Boolean available) {
	        this.available = available;
	    }

		public List<SysResource> getLowerResources() {
			return lowerResources;
		}

		public void setLowerResources(List<SysResource> lowerResources) {
			this.lowerResources = lowerResources;
		}

		public boolean isRootNode() {
	        return parentId == 0;
	    }
	    
	    public boolean isOneLevelMenu() {
	        return parentId == 1;
	    }

	    public String makeSelfAsParentIds() {
	        return getParentIds() + getId() + "/";
	    }
	    @Override
	    public boolean equals(Object o) {
	        if (this == o) return true;
	        if (o == null || getClass() != o.getClass()) return false;

	        SysResource resource = (SysResource) o;

	        if (id != null ? !id.equals(resource.id) : resource.id != null) return false;

	        return true;
	    }

	    @Override
	    public int hashCode() {
	        return id != null ? id.hashCode() : 0;
	    }

	    @Override
	    public String toString() {
	        return "Resource{" +
	                "id=" + id +
	                ", name='" + name + '\'' +
	                ", type=" + type +
	                ", permission='" + permission + '\'' +
	                ", parentId=" + parentId +
	                ", parentIds='" + parentIds + '\'' +
	                ", available=" + available +
	                '}';
	    }
}